<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<style>
  div {
    width: 20px;
    height: 20px;
    background: red;
    position: absolute;
  }
</style>
<script>
  document.onmousemove = function (event) {
    let divs = document.getElementsByTagName("div")

    for (let i = divs.length - 1; i > 0; i--) {
      divs[i].style.left = divs[i - 1].offsetLeft + "px"
      divs[i].style.top = divs[i - 1].offsetTop + "px"
    }
    divs[0].style.left = event.pageX + "px"
    divs[0].style.top = event.pageY + "px"
  }


</script>

<body>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>

</body>

</html>